//
//  PunchRecordViewController.m
//  云律司
//
//  Created by 韦淋 on 2017/7/31.
//  Copyright © 2017年 test. All rights reserved.
//

#import "PunchRecordViewController.h"


@interface PunchRecordViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *recordTableView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) NSArray *dklxArr;
@property (nonatomic, strong) NSArray *dktypeArr;
@property (nonatomic, strong) NSArray *dkflArr;
@end

@implementation PunchRecordViewController
- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
    //    self.automaticallyAdjustsScrollViewInsets = false;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.barTitleLable.text = @"考勤记录";
    self.dataSource = [NSMutableArray array];
    self.view.backgroundColor = [UIColor whiteColor];
    [self initUI];
    [self getData];
}
- (void)getData{
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [NetworkingManager getUrl:[NSString stringWithFormat:@"%@userid=%@",PUNCHCARDRECORD_URL,[InfoSingleTon personInfoSingleTon].infoDic[@"user"][@"id"]] dic:nil Succeed:^(id responseData){
        self.dataSource = responseData[@"result"];
        [self.recordTableView reloadData];
        NSLog(@"Data = %@",self.dataSource);
        [MBProgressHUD hideHUDForView:self.view animated:YES];
            
    } failure:^(NSError *error) {
        [MBProgressHUD showError:@"网络异常"];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
    
}
- (void)initUI{
    
    [self.view addSubview:self.recordTableView];
    
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PunchRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PunchRecordCell" forIndexPath:indexPath];
    cell.timeLable.text = self.dataSource[indexPath.row][@"daka_time"];
    cell.punchLXLable.text = self.dklxArr[[self.dataSource[indexPath.row][@"dakalx"] integerValue]  - 1];
    cell.punchTypeLable.text = self.dktypeArr[[self.dataSource[indexPath.row][@"dakatype"] integerValue] - 1];
    cell.punchFLLable.text = self.dkflArr[[self.dataSource[indexPath.row][@"dakafl"] integerValue] - 1] ;
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    return cell;
}

#pragma mark - Getter

- (UITableView *)recordTableView{
    if (!_recordTableView) {
        _recordTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 80, self.view.bounds.size.width, self.view.bounds.size.height - 80) style:UITableViewStylePlain];
        _recordTableView.backgroundColor = [UIColor clearColor];
        _recordTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _recordTableView.delegate = self;
        _recordTableView.dataSource = self;
        _recordTableView.estimatedRowHeight = 80;
        [_recordTableView registerClass:[PunchRecordCell class] forCellReuseIdentifier:@"PunchRecordCell"];
    }
    return _recordTableView;
}
- (NSArray *)dklxArr{
    if (!_dklxArr) {
        _dklxArr = [NSArray arrayWithObjects:@"上班",@"下班",nil];
    }
    return _dklxArr;
}
- (NSArray *)dktypeArr{
    if (!_dktypeArr) {
        _dktypeArr = [NSArray arrayWithObjects:@"公司范围内",@"公司范围外",nil];
    }
    return _dktypeArr;
}
- (NSArray *)dkflArr{
    if (!_dkflArr) {
        _dkflArr = [NSArray arrayWithObjects:@"正常",@"迟到",@"",@"",@"早退",@"",nil];
    }
    return _dkflArr;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
